using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class PostUserVotes : BasePage
{

    public override Acms.Bll.Role.Roles[] AllowedRoles
    {
        get { return new Acms.Bll.Role.Roles[] { Acms.Bll.Role.Roles.Developer, Acms.Bll.Role.Roles.ContentEditor, Acms.Bll.Role.Roles.ContentViewer, Acms.Bll.Role.Roles.UserGeneratedContentEditor }; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                postId = int.Parse(Request.QueryString["Id"]);
            }
            catch (FormatException)
            {
            }

            Acms.Bll.Post post = Acms.Bll.Post.GetById(postId);
            if (post != null)
            {
                postHeader.SetPost(post);
                Title = string.Format("User Votes for '{0}'", post.DisplayName);
            }
        }
    }

    private int postId;
    protected override object SaveViewState()
    {
        ViewState["PostId"] = postId;
        return base.SaveViewState();
    }

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["PostId"] is int)
            postId = (int)ViewState["PostId"];
    }

    protected void dsVotes_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.UserPostVote> e)
    {
        List<Acms.Bll.UserPostVote> votes = Acms.Bll.UserPostVote.GetByAllByPostId(postId);
        Acms.Bll.UserPostVote.Sort(votes, e.SortExpression);
        e.SetData(votes);
    }
}
